<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        class Person{
            #name;//私有属性
            age;//公有属性
            //构造方法
            constructor(name, age) {
                this.#name = name;
                this.age = age;
            }
            //get和set方法
            set name(name) {  
                this.#name = name;
            }
            set age(age) {
                this.age = age;
            }
            get name() {
                return this.#name;
            }
            get age() {
                return this.age;
            }
            eat(){
                console.log(`${this.age}岁的${this.#name}在吃饭`);
            }
            //静态方法
            static fun1(){
                console.log('这是静态方法');
            }
        }
        class Student extends Person {
            constructor(name, age, school) {
                super(name, age); //调用父类的构造方法
                this.school = school; //子类特有属性
            }
            study() {
                console.log(`${this.name}在${this.school}学习`);
            }
        }
        let person = new Person('张三', 18);
        console.log(person.name); // 张三
        console.log(person.age); // 18
        person.eat(); // 18岁的张三在吃饭
        Person.fun1(); // 这是静态方法
        person.name = '李四'; // 修改私有属性
        console.log(person.name)
        
    </script>
</head>
<body>
    
</body>
</html>